(function(vc){
    vc.extends({
        propTypes: {
           emitChooseProductPriceRule:vc.propTypes.string,
           emitLoadData:vc.propTypes.string
        },
        data:{
            chooseProductPriceRuleInfo:{
                productPriceRules:[],
                _currentProductPriceRuleName:'',
            }
        },
        _initMethod:function(){
        },
        _initEvent:function(){
            vc.on('chooseProductPriceRule','openChooseProductPriceRuleModel',function(_param){
                $('#chooseProductPriceRuleModel').modal('show');
                $that._refreshChooseProductPriceRuleInfo();
                $that._loadAllProductPriceRuleInfo(1,10,'');
            });
        },
        methods:{
            _loadAllProductPriceRuleInfo:function(_page,_row,_name){
                var param = {
                    params:{
                        page:_page,
                        row:_row,
                        communityId:vc.getCurrentCommunity().communityId,
                        name:_name
                    }
                };

                //发送get请求
               vc.http.apiGet('productPriceRule.listProductPriceRules',
                             param,
                             function(json){
                                var _productPriceRuleInfo = JSON.parse(json);
                                $that.chooseProductPriceRuleInfo.productPriceRules = _productPriceRuleInfo.productPriceRules;
                             },function(){
                                console.log('请求失败处理');
                             }
                           );
            },
            chooseProductPriceRule:function(_productPriceRule){
                if(_productPriceRule.hasOwnProperty('name')){
                     _productPriceRule.productPriceRuleName = _productPriceRule.name;
                }
                vc.emit($props.emitChooseProductPriceRule,'chooseProductPriceRule',_productPriceRule);
                vc.emit($props.emitLoadData,'listProductPriceRuleData',{
                    productPriceRuleId:_productPriceRule.productPriceRuleId
                });
                $('#chooseProductPriceRuleModel').modal('hide');
            },
            queryProductPriceRules:function(){
                $that._loadAllProductPriceRuleInfo(1,10,$that.chooseProductPriceRuleInfo._currentProductPriceRuleName);
            },
            _refreshChooseProductPriceRuleInfo:function(){
                $that.chooseProductPriceRuleInfo._currentProductPriceRuleName = "";
            }
        }

    });
})(window.vc);
